create view [fin].[eod_last_loads_v] as
WITH tab as (	SELECT		  exc.exc_cd
							, typ.cat_cd
							, lod.lod_status_desc
							, lod.lod_records_count
							, lod_trade_dt
							, lod.lod_id
							, ROW_NUMBER() OVER (PARTITION BY lcl.lcl_id ORDER BY lod.lod_trade_dt DESC) rn
				FROM		fin.eod_loads lod
							INNER JOIN	fin.eod_load_controls lcl
										ON (lod.lod_lcl_id = lcl.lcl_id)
							INNER JOIN	fin.eod_exchanges exc
										ON (lcl.lcl_exc_id = exc.exc_id)
							INNER JOIN	fin.com_categories typ
										ON (lcl.lcl_cat_load_type_id = typ.cat_id)
			)
SELECT		  exc_cd			AS llv_exc_cd
			, cat_cd			AS llv_cat_type_cd
			, lod_status_desc	AS llv_status_desc
			, lod_records_count	AS llv_records_count
			, lod_trade_dt		AS llv_trade_dt
			, lod_id			AS llv_lod_id
FROM		tab 
WHERE		tab.rn = 1;


